import request from './request'

// 工资数据类型
export interface SalaryData {
  id: number
  employeeId: string
  employeeName: string
  department: string
  position: string
  month: string
  baseSalary: number
  performanceBonus: number
  netSalary: number
  status: 'draft' | 'confirmed' | 'paid'
  remark?: string
  createTime: string
  updateTime: string
}

// 工资发放记录类型
export interface SalaryPaymentData {
  id: number
  salaryId: number
  paymentDate: string
  paymentAmount: number
  paymentMethod: 'bank_transfer' | 'cash' | 'alipay' | 'wechat'
  paymentStatus: 'pending' | 'processing' | 'completed' | 'failed'
  bankAccount?: string
  bankName?: string
  transactionNo?: string
  remark?: string
  createTime: string
  updateTime: string
}

// 获取工资分页列表
export const getSalaryPage = (params: {
  current: number
  size: number
  employeeName?: string
  department?: string
  month?: string
  status?: string
}) => {
  return request({
    url: '/salary/page',
    method: 'post',
    data: params
  })
}

// 获取工资列表
export const getSalaryList = (params?: { 
  month?: string
  employeeName?: string
  department?: string
  status?: string
}) => {
  return request({
    url: '/salary/list',
    method: 'post',
    data: params || {}
  })
}

// 获取工资详情
export const getSalaryDetail = (id: number) => {
  return request({
    url: '/salary/detail',
    method: 'post',
    data: { id }
  })
}

// 新增工资记录
export const addSalary = (salary: Omit<SalaryData, 'id' | 'createTime' | 'updateTime'>) => {
  return request({
    url: '/salary/add',
    method: 'post',
    data: salary
  })
}

// 编辑工资记录
export const updateSalary = (salary: SalaryData) => {
  return request({
    url: '/salary/update',
    method: 'post',
    data: salary
  })
}

// 删除工资记录
export const deleteSalary = (id: number) => {
  return request({
    url: '/salary/delete',
    method: 'post',
    data: { id }
  })
}

// 批量导入工资数据
export const importSalary = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/salary/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 确认工资
export const confirmSalary = (id: number) => {
  return request({
    url: '/salary/confirm',
    method: 'post',
    data: { id }
  })
}

// 发放工资
export const paySalary = (id: number) => {
  return request({
    url: '/salary/pay',
    method: 'post',
    data: { id }
  })
}

// 获取工资发放记录
export const getSalaryPayments = (salaryId: number) => {
  return request({
    url: '/salary/payments',
    method: 'post',
    data: { salaryId }
  })
}

// 新增工资发放记录
export const addSalaryPayment = (payment: Omit<SalaryPaymentData, 'id' | 'createTime' | 'updateTime'>) => {
  return request({
    url: '/salary/payment/add',
    method: 'post',
    data: payment
  })
}

// 更新工资发放状态
export const updatePaymentStatus = (id: number, status: string) => {
  return request({
    url: '/salary/payment/update-status',
    method: 'post',
    data: { id, status }
  })
}

// 获取工资统计
export const getSalarySummary = (params: {
  startMonth?: string
  endMonth?: string
  department?: string
}) => {
  return request({
    url: '/salary/summary',
    method: 'post',
    data: params
  })
}